package com.web.login;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.biz.IUserBiz;
import com.biz.UserBizImpl;
import com.entity.UserInfo;

public class CheckRegServlet extends HttpServlet {

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		doPost(request, response);
	}

	/**
		 * The doPost method of the servlet. <br>
		 *
		 * This method is called when a form has its tag value method equals to post.
		 * 
		 * @param request the request send by the client to the server
		 * @param response the response send by the server to the client
		 * @throws ServletException if an error occurred
		 * @throws IOException if an error occurred
		 */
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=utf-8");
		PrintWriter out = response.getWriter();
		request.setCharacterEncoding("utf-8");
		UserInfo us=new UserInfo();
		String uname=request.getParameter("uname");
		String email=request.getParameter("email");
		String phone=request.getParameter("phone");
		us.setUname(uname);
		us.setEmail(email);
		us.setPhone(phone);
		IUserBiz ubiz=new UserBizImpl();
		
		String res=ubiz.checkInfo(us.getUname(), us.getPhone(), us.getEmail());
		if(!res.equals("")){
			if(res.equals(uname)){
				out.print("用户名已被注册");
			}else if(res.equals(phone)){
				out.print("电话号码已被注册");
			}else{
				out.print("邮箱已被注册");
			}
		}else{
			out.print("");
		}
		out.flush();
		out.close();
	}

}
